package com.example.administrator.himalaya.criticallies;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.himalaya.R;
import com.example.administrator.himalaya.adapter.SubscibeAdapter;
import com.example.administrator.himalaya.fragment.downloadFragment.FragmentDownloadDownloading;
import com.example.administrator.himalaya.fragment.downloadFragment.FragmentDownloadSpecial;
import com.example.administrator.himalaya.fragment.downloadFragment.FragmentDownloadVoice;

import java.util.ArrayList;
import java.util.List;


/**
 * A simple {@link Fragment} subclass.
 * 下载听
 */
public class DownloadFragment extends Fragment {


    private TabLayout download_tab;
    private ViewPager download_pager;
    private List<Fragment> fragments;
    private List<String> title;

    public DownloadFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_download, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        download_tab = ((TabLayout) view.findViewById(R.id.download_tab));
        download_pager = ((ViewPager) view.findViewById(R.id.download_pager));
        download_tab.setupWithViewPager(download_pager);

        fragments = new ArrayList<>();
        fragments.add(new FragmentDownloadSpecial());
        fragments.add(new FragmentDownloadVoice());
        fragments.add(new FragmentDownloadDownloading());
        title = new ArrayList<>();
        title.add("专辑");
        title.add("声音");
        title.add("下载中");

        SubscibeAdapter subscibeAdapter = new SubscibeAdapter(getChildFragmentManager(), title, fragments, getContext());
        download_pager.setAdapter(subscibeAdapter);
        download_tab.setupWithViewPager(download_pager);
        download_pager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(download_tab));

    }
}
